﻿Imports OpenTK.Graphics.OpenGL
Imports OpenTK

Public Class PathCreated
    Private localmR As OGL
    Private colors(7) As Double
    Public indexc As Integer = 0
    Public indexv As Integer = 0
    'Private mColorBuffer() As Double = {}
    Private mVertexBuffer() As Double = {}


    Private posicionActual As Integer = 0


    Public Sub New(ByVal paramWorldRenderer As OGL)
        localmR = paramWorldRenderer
        mVertexBuffer = New Double(800000) {}
        'mColorBuffer = New Double(800000) {}
        colors(0) = 0.0F
        colors(1) = 1.0F
        colors(2) = 0.0F
        colors(3) = 0.5F
        colors(4) = 0.0F
        colors(5) = 1.0F
        colors(6) = 0.0F
        colors(7) = 0.5F

        'mColorBuffer = colors
    End Sub

    Public Overridable Sub addPoint(ByVal paramFloat1 As Double, ByVal paramFloat2 As Double, ByVal paramFloat3 As Double, ByVal paramFloat4 As Double, ByVal paramFloat5 As Double, ByVal paramFloat6 As Double, ByVal paramInt1 As Double, ByVal paramInt2 As Double, ByVal paramInt3 As Double, ByVal paramInt4 As Double)
        mVertexBuffer(indexv + 0) = paramFloat1
        mVertexBuffer(indexv + 1) = paramFloat2
        mVertexBuffer(indexv + 2) = paramFloat3
        mVertexBuffer(indexv + 3) = paramFloat4
        mVertexBuffer(indexv + 4) = paramFloat5
        mVertexBuffer(indexv + 5) = paramFloat6
      
        indexv = (6 + indexv)
        indexc = (6 + indexc)

    End Sub

    Public Overridable Sub drawComplete()
        GL.Enable(EnableCap.Blend)
        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha)
        If indexc Mod 12 = 0 Then
            GL.Begin(BeginMode.TriangleStrip)
            GL.Color4(0.0F, 1.0F, 0.0F, 0.5F)
            For i = 12 To indexc Step 12

                If mVertexBuffer(i - 12) <> 0.0 And mVertexBuffer(i - 1) <> 0.0 Then
                    GL.Vertex3(mVertexBuffer(i - 12), mVertexBuffer(i - 11), mVertexBuffer(i - 10))
                    GL.Vertex3(mVertexBuffer(i - 9), mVertexBuffer(i - 8), mVertexBuffer(i - 7))
                    GL.Vertex3(mVertexBuffer(i - 6), mVertexBuffer(i - 5), mVertexBuffer(i - 4))
                    GL.Vertex3(mVertexBuffer(i - 3), mVertexBuffer(i - 2), mVertexBuffer(i - 1))
                End If

            Next i

            GL.End()


        End If
    End Sub
    Public Overridable Sub draw()
        GL.Enable(EnableCap.Blend)
        GL.BlendFunc(BlendingFactorSrc.SrcAlpha, BlendingFactorDest.OneMinusSrcAlpha)

        If (indexc > 12) Then
            If ((localmR.flagMarcar) And (localmR.flagMarcarFalse)) Then
                posicionActual = indexc
                localmR.flagMarcarFalse = False
           

            End If

            GL.Begin(BeginMode.TriangleStrip)
            GL.Color4(0.0F, 1.0F, 0.0F, 0.5F)

            For i = posicionActual To indexc Step 12
               
                GL.Vertex3(mVertexBuffer(i - 12), mVertexBuffer(i - 11), mVertexBuffer(i - 10))
                GL.Vertex3(mVertexBuffer(i - 9), mVertexBuffer(i - 8), mVertexBuffer(i - 7))
                GL.Vertex3(mVertexBuffer(i - 6), mVertexBuffer(i - 5), mVertexBuffer(i - 4))
                GL.Vertex3(mVertexBuffer(i - 3), mVertexBuffer(i - 2), mVertexBuffer(i - 1))
            Next i

            GL.End()

           
            



        End If


        'GL.BufferData(BufferTarget.ArrayBuffer, New IntPtr(12 * indexv), IntPtr.Zero, BufferUsageHint.StreamDraw) ' Clear the old buffer
        'GL.BufferData(BufferTarget.ArrayBuffer, New IntPtr(12 * indexv), indexv, BufferUsageHint.StreamDraw) ' Upload the new buffer
        'GL.BufferData(Of Vector4)(BufferTarget.ArrayBuffer, CType(colourBuffer.Length * Vector4.SizeInBytes, IntPtr), colourBuffer, BufferUsageHint.StreamDraw)
        'GL.DrawArrays(BeginMode.LineStrip, 0, indexv) ' Draw the Array in LineStrip mode


       



    End Sub
End Class
